module.exports = function (sequelize) {
    var model = sequelize.define("resources", {
            "resCode": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: false,
                primaryKey: true,
                comment: "资源编号"
            },
            "resParentCode": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: false,
                comment: "父级资源编号"
            },
            "resIcon": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: true,
                comment: "图标"
            },
            "resName": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: true,
                comment: "资源名称"
            },
            "resType": {
                type: sequelize.DataTypes.CHAR(1),
                comment: "资源类型"
            },
            "resHref": {
                type: sequelize.DataTypes.STRING(100),
                allowNull: true,
                comment: "资源链接"
            },
            "resSort": {
                type: sequelize.DataTypes.INTEGER(5),
                allowNull: true,
                defaultValue: 0,
                comment: "资源排序"
            },
            "isClose": {
                type: sequelize.DataTypes.CHAR(1),
                allowNull: true,
                defaultValue: "0",
                comment: "是否存在关闭按钮"
            },
            "initOpen": {
                type: sequelize.DataTypes.CHAR(1),
                allowNull: true,
                defaultValue: "0",
                comment: "是否默认打开"
            }
        },
        {
            "tableName": "resources"
        });

    model.initRelation = function () {
        model.belongsTo(db.models.trueFalse, {foreignKey: "initOpen", constraints: false});
        model.belongsTo(db.models.trueFalse, {foreignKey: "isClose", constraints: false});
        model.belongsTo(db.models.resources, {foreignKey: "resParentCode", constraints: false});
        model.belongsTo(db.models.resType_, {foreignKey: "resType", constraints: false});
    }

    model.initData = new Array();
    model.initData.push({
        resCode: "WELCOME",
        resParentCode: undefined,
        resName: "首页",
        resIcon: "menu-icon glyphicon glyphicon-home",
        resType: "1",
        resHref: "/welcome.html",
        resSort: 0,
        isClose: "0",
        initOpen: "1"
    });
    model.initData.push({
        resCode: "SYS_MANAGER",
        resParentCode: undefined,
        resName: "系统管理",
        resIcon: "menu-icon fa fa-desktop",
        resType: "1",
        resHref: "###",
        resSort: 1,
        isClose: "0",
        initOpen: "0"
    });
    model.initData.push({
        resCode: "SYS_USER_MANAGER",
        resParentCode: "SYS_MANAGER",
        resName: "用户管理",
        resIcon: "menu-icon fa fa-rocket",
        resType: "1",
        resHref: "/users.html",
        resSort: 2,
        isClose: "1",
        initOpen: "0"
    });

    model.initData.push({
        resCode: "TEST_UPLOAD_FILES",
        resParentCode: undefined,
        resName: "上传图片测试",
        resIcon: "menu-icon glyphicon glyphicon-home",
        resType: "1",
        resHref: "/uploadFiles.html",
        resSort: 3,
        isClose: "1",
        initOpen: "0"
    });
}